#include <iostream>
#include <set>
#include <vector>
#include <numeric>
#include <cmath>
#include <algorithm>

using namespace std;

static int fuck(const int n) {
    set<int> s {};
    for (int i = 2; i <= static_cast<int>(sqrt(n)); ++i) {
        if (n % i == 0) {
            s.insert(i);
            s.insert(n / i);
        }
    }
    return accumulate(s.begin(), s.end(), 1);
}

static void vector_show(const vector<int>& v) {
    for (auto e : v)
        cout << e << ' ';
    cout << endl;
}

int main() {
    constexpr int limit = 1'000'000;
    vector<int> v {0, 0, 1, 1, 3};
    for (int i = v.size(); i <= limit; ++i) 
        v.push_back(fuck(i));

    int len = 0;
    int ans = 0;
    for (int i = 0; i < v.size(); ++i) {
        vector<int> a {i};
        while (true) {
            a.push_back(v[a.back()]);
            if (a.back() == a[0] && a.size() > len) {
                vector_show(a);
                len = a.size();
                ans = a.back();
            }
            
            if (count(a.begin(), a.end(), a.back()) > 1)
                break;
            if (a.back() > limit)
                break;
            if (a.back() == v[a.back()])
                break;
            if (a.back() == 0)
                break;
            if (a.back() == 1)
                break;
        }
    }
    cout << ans << endl;
}   // 14316